#include <assert.h>
#include <stdio.h>

int is_prime(int n)
{
	int j = 0;
	for (j = 2; j <= sqrt(n); j++)
	{
		if (n % j == 0)
		{
			return 0;//不是素数
		}
	}
	return 1;//是素数
}
int main()
{
	int i = 0;
	for (i = 100; i <= 200; i++)
	{
		//判断i是否为素数
		if (is_prime(i))
		{
			printf("%d ", i);
		}
	}

	return 0;
}

int is_leap_year(int y)
{
	if (y % 4 == 0 && y % 100 != 0)
	{
		return 1;
	}
	if (y % 400 == 0)
	{
		return 1;
	}

	return 0;
}

int is_leap_year(int y)
{
	if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0))
		return 1;
	else
		return 0;
}

int is_leap_year(int y)
{
	return (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0));
}

int main()
{
	int y = 0;
	for (y = 1000; y <= 2000; y+=4)
	{
		//判断y是否为闰年
		//是闰年返回1
		//不是闰年返回0
		if (is_leap_year(y))
		{
			printf("%d ", y);
		}
	}
	return 0;
}


int binary_search(int arr[], int k, int sz)
{
	int left = 0;
	int right = sz - 1;

	while (left<=right)
	{
		int mid = (left + right) / 2;
		if (arr[mid] < k)
		{
			left = mid + 1;
		}
		else if (arr[mid] > k)
		{
			right = mid - 1;
		}
		else
		{
			return mid;
		}
	}
	return -1;//找不到
}

int main()
{
	int arr[] = { 1,2,3,4,5,6,17,18,19,20,21 };//10
	//0~9
	int k = 21;
	//找到了就返回下标
	//找不到返回-1
	//计算数组的元素个数
	int sz = sizeof(arr) / sizeof(arr[0]);
	int pos = binary_search(arr, k, sz);
	if (-1 == pos)
		printf("找不到\n");
	else
		printf("找到了，下标是:%d\n", pos);

	return 0;
}

void Add(int* p)
{
	//*p = *p+1;
	(*p)++;
}

int main()
{
	int num = 0;
	Add(&num);
	printf("%d\n", num);//1
	Add(&num);
	printf("%d\n", num);//2
	Add(&num);
	printf("%d\n", num);//3
	return 0;
}

#include <string.h>

int main()
{
	//int len = strlen("abcdef");
	printf("%d\n", strlen("abcdef"));

	return 0;
}

int main()
{
	printf("%d", printf("%d", printf("%d", 43)));

	return 0;
}

char * strcpy(char*dst,char*src)
{
	char * cp = dst;
	assert(dst&&src);

	while(*cp++=*src++)
		;
	return dst;
}

int my_strlen(const char*str)
{
	int count = 0;
	assert(str!=NULL);
	while (*str)
	{
		count++;
		str++;
	}
	return count;
}

int main()
{
	const char*p="abcdef";
	int len = my_strlen(p);
	printf("len=%d\n",len);
	return 0;
}

void print(int n)
{
	if(n>9)
		printf(n/10);
	printf("%d ",n%10);
}

int main()
{
	int num = 1234;
	print(num);
	return 0;
}

int Strlen(const char*str)
{
	if(*str=='\0')
		return 0;
	else
		return 1+Strlen(str+1);
}

int main()
{
	char *p = "ABCDEF";
	int len = Strlen(p);
	printf("%d\n",len);
	return 0;
}

int factorial(int n)
{
	if(n<=1)
		return 1;
	else
		return n*factorial(n-1);
}

int fib(int n)
{
	int result;
	int pre_result;
	int next_result;
	result = pre_result = 1;
	while(n>2)
	{
		n=n-1;
		next_result = pre_result;
		pre_result = result;
		result = pre_result+next_result;
	}
	return result;
}
















